package com.yuntu.service;

import com.yuntu.mapper.Dev_userMapper;
import com.yuntu.pojo.Dev_user;
import com.yuntu.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class Dev_userServiceImpl implements Dev_userService{
    @Autowired
    private Dev_userMapper devMapper;
    @Override
    public Dev_user login(String devCode, String devPassword) throws Exception {
        Dev_user dev_user = devMapper.login(devCode);
        if (dev_user != null) {
            if (!dev_user.getDevPassword().equals(devPassword)) {
                dev_user = null;
            }
        }
        return dev_user;
    }

    @Override
    public void getDev_userPageAll(PageUtil<Dev_user> pageUtil) throws Exception {
        int count=devMapper.getCount();
        pageUtil.setCounts(count);
        if (count>0){
            if (pageUtil.getPageindex()>pageUtil.getPagecount()){
                pageUtil.setPageindex(pageUtil.getPagecount());
            }
            pageUtil.setLists(devMapper.getDev_userPageAll(pageUtil));
        }else{
            pageUtil.setLists(new ArrayList<>());
        }
    }

    @Override
    public int delDev(int id) {
        return devMapper.delDev(id);
    }

    @Override
    public Dev_user isRepeat(String devCode) {
        return devMapper.isRepeat(devCode);
    }

    @Override
    public int addDev(Dev_user dev_user) {
        return devMapper.addDev(dev_user);
    }

    @Override
    public Dev_user selDev(int id) {
        return devMapper.selDev(id);
    }

    @Override
    public int updDev(Dev_user dev_user) {
        return devMapper.updDev(dev_user);
    }

}
